<?php

/**
 * model_inform
 */

class Model_inform extends YOU {

	public function __construct()
	{
		parent::__construct();
	}

	/** 读取总数 **/
	public function count()
	{
		$row = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform`");
		return (int)$row['count'];
	}

	/** 读取列表 **/
	public function getAll($field = "*")
	{
		$inform_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_inform` ");

		return $inform_lists;
	}
	/** 读取信息 **/
	public function getinfo($inform_id, $field = "*")
	{	
		$inform_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform` WHERE inform_id='{$inform_id}'");

		return $inform_data;
	}
	/** 读取通知样式全部信息 **/
	public function getstyleAll( $field = "*")
	{
		$style_lists = $this->db->fetchAll("SELECT {$field} FROM `tbl_inform_style`");

		return $style_lists;
	}
	/** 读取通知样式单条信息 **/
	public function getstyleinfo( $style_id ,$field = "*")
	{
		$style_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform_style` WHERE style_id = {$style_id}");

		return $style_data;
	}
	/** 读取默认通知样式信息 **/
	public function getstylemo($field = "*")
	{
		$style_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform_style` WHERE style_mo = '1'");

		return $style_data;
	}
	/** 部门阅读人 **/
	public function getReadAll($inform_id, $field = "*")
	{
		$read_data = $this->db->fetchAll("SELECT {$field} FROM `tbl_inform_read` WHERE inform_id ={$inform_id}");

		return $read_data;
	}
	/** 部门阅读人(参数教师id) **/
	public function getReadInfo($staff_id, $field = "*")
	{	
			
		$read_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform_read` WHERE  read_to = '{$staff_id}'");
	
		return $read_data;
	}
	/** 部门阅读人 **/
	public function getReadRow($inform_id,$user_id, $field = "*")
	{	
		
		$read_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform_read` WHERE inform_id ='{$inform_id}' AND read_to = '{$user_id}'");

		return $read_data;
	}
	/** 部门阅读人(参数教师id) **/
	public function getReadIn($staff_id, $field = "*")
	{	
			
		$inform_data = $this->db->fetchRow("SELECT {$field} FROM `tbl_inform_read` WHERE  read_to = '{$staff_id}'");

		return $inform_data;
	}
	/** 首页上级通知 **/
	public function getIndexlist($user_id, $inform_type, $num, $field = "*")
	{
		$inform_lists = $this->db->fetchAll("SELECT a.*,b.* FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND b.read_to={$user_id} AND a.inform_type='{$inform_type}'  ORDER BY b.is_read ASC,a.inform_id DESC LIMIT 0,{$num}");
		
		foreach($inform_lists  as $key => $value){
				$department_data = $this->db->fetchRow("SELECT * FROM `tbl_department_up` WHERE up_id={$value['up_id']}");
				$inform_lists[$key]['department_name'] = $department_data['up_name'];
				$inform_lists[$key]['create_time'] =date('m-d H:i',strtotime($value['create_time']));
			}
		return $inform_lists;
	}
    /** 首页上级通知 **/
    public function getIndexcount($user_id, $inform_type, $num, $field = "*")
    {
    
        $inform_data = $this->db->fetchRow("SELECT count(1) as count FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND b.read_to={$user_id} AND a.inform_type='{$inform_type}' AND b.is_read = '0' ORDER BY a.inform_id DESC");

        return $inform_data['count'];
    }
    /** 首页上级通知提醒 **/
	public function getIndexSixlist($user_id, $inform_type, $num, $field = "*")
	{
		$inform_lists = $this->db->fetchAll("SELECT a.*,b.* FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND b.read_to={$user_id} AND a.inform_type='{$inform_type}' AND b.is_show ='0'  ORDER BY b.is_read ASC,a.inform_id DESC LIMIT 0,{$num}");
		
		foreach($inform_lists  as $key => $value){
				$department_data = $this->db->fetchRow("SELECT * FROM `tbl_department_up` WHERE up_id={$value['up_id']}");
				$inform_lists[$key]['department_name'] = $department_data['up_name'];
				$inform_lists[$key]['create_time'] =date('m-d H:i',strtotime($value['create_time']));
			}
		return $inform_lists;
	}
    /** 首页提醒(总数) **/
	public function getIndexSixCount($user_id, $inform_type, $num, $field = "*")
	{
		
		$data = $this->db->fetchRow("SELECT COUNT(1) AS count FROM `tbl_inform` AS a,`tbl_inform_read` AS b WHERE a.inform_id = b.inform_id AND b.read_to = '{$user_id}' AND a.inform_type='{$inform_type}' AND b.is_show ='0' ");

		return $data;
	}
}



?>